﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Negocios;

public partial class ManterSoftwareDeReproducao : System.Web.UI.Page
{
    Software_De_ReproducaoBLL sdrBLL = new Software_De_ReproducaoBLL();
        
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnNovo_Click(object sender, EventArgs e)
    {
        txtFabricante.Enabled = true;
        txtNome.Enabled = true;
        rblTipo.Enabled = true;
        btnCancelar.Enabled = true;
        btnGravar.Enabled = true;
        btnNovo.Enabled = false;
    }

    public void limpar() {
        txCodigo.Text = "";
        txtNome.Text = "";
        txtFabricante.Text = "";
        txtFabricante.Enabled = false;
        txtNome.Enabled = false;
        rblTipo.Enabled = false;
        btnCancelar.Enabled = false;
        btnGravar.Enabled = false;
        lblErro.Text = "";

    
    }
    protected void btnGravar_Click(object sender, EventArgs e)
    {

        try
        {
            if (txCodigo.Text == "")
            {
                Software_De_ReproducaoBLL softwareBLL = new Software_De_ReproducaoBLL();
                SoftwareDeReproducao software = new SoftwareDeReproducao(txtNome.Text,
                txtFabricante.Text, Convert.ToInt32(rblTipo.SelectedValue));
                softwareBLL.Insere(software);
                limpar();
                btnNovo.Enabled = true;
                GridView1.DataBind();
            }
            else
            {
                Software_De_ReproducaoBLL softwareBLL = new Software_De_ReproducaoBLL();
                SoftwareDeReproducao software = new SoftwareDeReproducao(txtNome.Text,
                txtFabricante.Text, Convert.ToInt32(rblTipo.SelectedValue));
                softwareBLL.Atualizar(software);
            }
        }
        catch (Exception ex) {
            lblErro.Text = ex.Message;        
        }
    }
    protected void btnCancelar_Click(object sender, EventArgs e)
    {
        limpar();
        btnNovo.Enabled = true;
    }
    protected void lbAtualiza_Click(object sender, EventArgs e)
    {
        try
        {
            int id = Convert.ToInt32(((GridViewRow)((DataControlFieldCell)((LinkButton)sender).Parent).Parent).Cells[0].Text);
            SoftwareDeReproducao sdr = sdrBLL.Consulta(id);
            txtNome.Enabled = true;
            txtFabricante.Enabled = true;
            rblTipo.Enabled = true;
            btnGravar.Enabled = true;
            btnCancelar.Enabled = true;
            btnNovo.Enabled = false;

            txCodigo.Text = sdr.Codigo.ToString();
            txtNome.Text = sdr.Nome;
            txtFabricante.Text = sdr.Fabricante;
            rblTipo.SelectedValue = sdr.Tipo.ToString();
            GridView1.DataBind();
        }
        catch (Exception ex) {
            lblErro.Text = ex.Message;        
        }
    }
    protected void lbRemove_Click(object sender, EventArgs e)
    {
        try
        {
            int id = Convert.ToInt32(((GridViewRow)((DataControlFieldCell)((LinkButton)sender).Parent).Parent).Cells[0].Text);
            SoftwareDeReproducao sdr = new SoftwareDeReproducao(id);
            Software_De_ReproducaoBLL sdrBLL = new Software_De_ReproducaoBLL();
            sdrBLL.Excluir(sdr);
            GridView1.DataBind();
        }
        catch (Exception ex) { 
         lblErro.Text = ex.Message;
        }
    }
    
}

        
        
        

        
   